/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 123
 * Date: 2023-05-24
 * Time: 8:57
 */



public class test {


    public static void main(String[] args) {
         MyList myList = new MyList();
        myList.addNode(1);
        myList.addNode(2);
        myList.addNode(4);
        myList.diPlay();
        MyList myList2 = new MyList();
        myList2.addNode(1);
        myList2.addNode(3);
        myList2.addNode(4);
        myList2.diPlay();
      MyList myList3 = new MyList();

        myList3.head = mergeTwoLists(myList.head ,myList2.head);

      myList.diPlay();
      myList2.diPlay();
        myList3.diPlay();
    }
    public static MyList.ListNode mergeTwoLists(MyList.ListNode list1, MyList.ListNode list2) {
        if(list1 == null){
            return list2 ;
        }
        if(list2 == null){
            return list1 ;
        }
        if(list1.val < list2 .val){
            list1.next = mergeTwoLists(list1.next ,list2);
            return list1 ;
        }else{
            list2.next = mergeTwoLists(list1,list2.next);
            return list2 ;
        }
    }
}


